//
//  PicturePurTableViewCell.m
//  GLGW_Shoping
//
//  Created by yang on 2018/11/14.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "PicturePurTableViewCell.h"
#import "YLJCollectionViewFlowLayout.h"
#import "PicImageViewCollectionViewCell.h"

@interface PicturePurTableViewCell ()<UICollectionViewDelegate,UICollectionViewDataSource,YLJCollectionViewFlowLayoutDelegate>

@end

@implementation PicturePurTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        YLJCollectionViewFlowLayout *flow_Layout = [[YLJCollectionViewFlowLayout alloc] init];
        flow_Layout.delegate = self;
        UICollectionView * pictureCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(kWidthProportion_In_iPhoneTriploid(15), 0, KScreenWidth-kWidthProportion_In_iPhoneTriploid(30), kHeightProportion_In_iPhoneTriploid(117)) collectionViewLayout:flow_Layout];
        pictureCollectionView.delegate = self;
        pictureCollectionView.dataSource = self;
        pictureCollectionView.backgroundColor = [UIColor whiteColor];
        [pictureCollectionView registerClass:[PicImageViewCollectionViewCell class] forCellWithReuseIdentifier:[PicImageViewCollectionViewCell cellIdentifier]];
        [self addSubview:pictureCollectionView];
    }
    return self;
}

#pragma mark -- UICollectionViewDelegate,UICollectionViewDataSource,YLJCollectionViewFlowLayoutDelegate
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 3;
}

-(ZLLayoutType)collectionView:(UICollectionView *)collectionView layout:(YLJCollectionViewFlowLayout *)collectionViewLayout typeOfLayout:(NSInteger)section{
    return ClosedLayout;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    PicImageViewCollectionViewCell * cell = [PicImageViewCollectionViewCell cellWithCollectionView:collectionView forIndexPath:indexPath];
    return cell;
}

//如果是百分比布局必须实现该代理，设置每个item的百分比，如果没实现默认比例为1
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(YLJCollectionViewFlowLayout*)collectionViewLayout percentOfRow:(NSIndexPath*)indexPath{
    return 1;//最多4个图片
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake(collectionView.frame.size.width/4, collectionView.height);
}

//如果是ClosedLayout样式的section，必须实现该代理，指定列数
- (NSInteger)collectionView:(UICollectionView *)collectionView layout:(YLJCollectionViewFlowLayout*)collectionViewLayout columnCountOfSection:(NSInteger)section{
    return 3;
}

//如果是绝对定位布局必须是否该代理，设置每个item的frame
- (CGRect)collectionView:(UICollectionView *)collectionView layout:(YLJCollectionViewFlowLayout*)collectionViewLayout rectOfItem:(NSIndexPath*)indexPath{
    return CGRectZero;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView layout:(YLJCollectionViewFlowLayout *)collectionViewLayout zIndexOfItem:(NSIndexPath*)indexPath{
    return 0;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return 0;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return kWidthProportion_In_iPhoneTriploid(15);
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{//top, left, bottom, right;
    return UIEdgeInsetsMake(kHeightProportion_In_iPhoneTriploid(22), kWidthProportion_In_iPhoneTriploid(10), kHeightProportion_In_iPhoneTriploid(20), kWidthProportion_In_iPhoneTriploid(10));
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
